#ifndef _BufFifo_h_
#define _BufFifo_h_

#ifndef TRUE
#	define TRUE 	1
#endif

#ifndef FALSE
#	define FALSE 	0
#endif


typedef struct SBufFifo
{
	uint8_t in;
	uint8_t out;
	uint8_t size;
	uint8_t buf[1];
}
sBufFifo, *psBufFifo;

enum
{
	FIFO_OK,
	FIFO_ERR = -1	// Same as stdio EOF
};

#define BUFF_DECL_FIFO(Name, Size)					\
uint8_t Name##Fifo[Size + sizeof(sBufFifo) - 1];	\
const psBufFifo Name = (psBufFifo)Name##Fifo;		\
static const uint8_t Name##FifoSz = Size;

#define BUFF_INIT_FIFO(Name)		\
	BuffFlushFifo(Name);			\
	Name->size = Name##FifoSz

#define BUFF_EXT_FIFO(Name)			\
	extern uint8_t Name##Fifo[];	\
	static const psBufFifo Name = (psBufFifo)Name##Fifo

int16_t BuffPutFifo(psBufFifo, uint8_t);
int16_t BuffPullFifo(psBufFifo);
void BuffWaitPutFifo(psBufFifo, uint8_t);
int16_t BuffWaitPullFifo(psBufFifo);
int16_t BuffPeekFifo(psBufFifo);
int16_t BuffStatFifo(psBufFifo);
void BuffFlushFifo(psBufFifo);

#endif	// _BufFifo_h_
